package cn.est.controller;

import cn.est.dto.ModelReq;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.pojo.Model;
import cn.est.service.ModelService;
import cn.est.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api
@RestController
@RequestMapping("/api/model")
public class ModelController {

    @Autowired
    ModelService modelService;




    @ApiOperation(value="商品的列表搜索",notes = "商品的型号列表分页显示")
    @GetMapping("/search")
    public Result list(ModelReq modelReq){

        if(modelReq.getPageNo()==null){
            modelReq.setPageNo(1);
        }
        if(modelReq.getPageSize()==null){
            modelReq.setPageNo(20);
        }
       Page<Model> modelPage=  modelService.getModelPage(modelReq);
        return ResultUtils.returnDataSuccess(modelPage);
    }


    @ApiOperation(value="商品的详情",notes = "根据id查询商品的详细信息")
    @ApiImplicitParam(name = "id",value = "商品型号Id",required = true)
    @GetMapping("{id}/detail")
    public Result<Model> detail(@PathVariable Long id){
        Model model =modelService.getModelById(id);
        return  ResultUtils.returnDataSuccess(model);
    }


}
